package org.expath.httpclient.test.server;

import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.expath.httpclient.test.server.TestRequest.Failure;

/**
 *
 * @author Florent Georges
 */
public class EmptyBodyAsserter
        implements BodyAsserter
{
    public boolean assertIt(HttpServletRequest req, Failure f)
            throws ServletException
    {
        try {
            InputStream in = req.getInputStream();
            if ( in.read() != -1 ) {
                f.add("Body is not empty...");
                return false;
            }
            return true;
        }
        catch ( IOException ex ) {
            throw new ServletException(ex);
        }
    }
}
